﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using MathExpressionSolver.App_Code;

namespace MathExpressionSolver
{
    public partial class SimpleCalculator : System.Web.UI.Page
    {
        //*************************************************
        //                  Page Load
        //*************************************************
        #region Page Load
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        #endregion
        //*************************************************



        //*************************************************
        //                   Buttons
        //*************************************************
        #region Buttons
        protected void btnEquals_Click(object sender, EventArgs e)
        {
            lblResult.ForeColor = System.Drawing.Color.Red;

            if (!Validation_Functions.IsDecimal(txtNum1.Text))
            {
                lblResult.Text = string.Format(@"The first value (""{0}"") is not a number!", txtNum1.Text);
            }
            else if (!Validation_Functions.IsDecimal(txtNum2.Text))
            {
                lblResult.Text = string.Format(@"The second value (""{0}"") is not a number!", txtNum2.Text);
            }
            else if ((Validation_Functions.IsDecimal(txtNum1.Text)) && (Validation_Functions.IsDecimal(txtNum1.Text)))
            {
                lblResult.ForeColor = System.Drawing.Color.Black;

                lblResult.Text = string.Format("{0}", Math_Functions.SimpleEval(txtNum1.Text, txtNum2.Text, cmbOperators.SelectedValue[0]));
            }
        }
        #endregion
        //*************************************************
    }
}